package com.neusoft.hifly.message.msg.entity;

import java.io.Serializable;
import java.time.LocalDateTime;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;

import com.neusoft.hifly.commons.lang.LocalDateUtil;
import com.neusoft.hifly.commons.lang.StringConstants;
import com.neusoft.hifly.core.utils.GlobalConstants;

/**
 * Title: 消息服务
 * <p>
 * Description: 收件箱对象
 * <p>
 * Copyright: 2019
 * <p>
 * Company: 东软汉枫
 *
 * @author lh_neu
 * @version 1.0.0
 */
@JsonIgnoreProperties(ignoreUnknown = true)
@TableName(value = GlobalConstants.DYNAMIC_TABLE_NAME_PREFIX + "_MSG_INBOX")
public class MsgInboxObj implements Serializable {
	private static final long serialVersionUID = -156101013402034L;
	// 主键
	@TableId(value = "ID")
	private long id;
	// 逻辑ID
	@TableField(value = "LOGIC_ID")
	private long logicId;
	// 租户逻辑ID
	@TableField(value = "ORGAN_LOGIC_ID")
	private long organLogicId;
	// 父消息逻辑ID
	@TableField(value = "MSG_LOGIC_ID")
	private long msgLogicId;
	// 消息状态（默认0未读/1已读）
	@TableField(value = "MSG_STATUS")
	private String msgStatus;
	// 接收人ID
	@TableField(value = "USER_ID")
	private long userId;
	// 接收人名称
	@TableField(value = "USER_NAME")
	private String userName;
	// 接收时间
	@TableField(value = "RECEIVE_TIME")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonDeserialize(using = LocalDateTimeDeserializer.class)
	@JsonSerialize(using = LocalDateTimeSerializer.class)
	private LocalDateTime receiveTime;
	// 消息类型
	@TableField(value = "MSG_TYPE")
	private String msgType;
	// 业务表单的ID
	@TableField(value = "OBJ_ID")
	private long objId;
	// 系统编码
	@TableField(value = "SYS_CODE")
	private String sysCode;
	// 修改人
	@TableField(value = "UPDATE_PERSON")
	private String updatePerson;
	// 修改时间
	@TableField(value = "UPDATE_TIME")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonDeserialize(using = LocalDateTimeDeserializer.class)
	@JsonSerialize(using = LocalDateTimeSerializer.class)
	private LocalDateTime updateTime;
	// 扩展字段1
	@TableField(value = "EXT1")
	private String ext1;
	// 扩展字段2
	@TableField(value = "EXT2")
	private String ext2;
	// 扩展字段3
	@TableField(value = "EXT3")
	private String ext3;
	// 扩展字段4
	@TableField(value = "EXT4")
	private String ext4;
	// 扩展字段5
	@TableField(value = "EXT5")
	private String ext5;

	// ################### 临时数据 ####################

	// 格式化后的字符串日期
	@TableField(exist = false)
	private String updateTimeStr;
	// 消息状态（默认0未读/1已读）
	@TableField(exist = false)
	private String msgStatusStr;
	// 接收时间
	@TableField(exist = false)
	private String receiveTimeStr;

	// 标题
	@TableField(exist = false)
	private String msgTitle;
	// 内容
	@TableField(exist = false)
	private String msgContent;
	// 发送类型
	@TableField(exist = false)
	private String sendType;
	// 发送日期
	@TableField(exist = false)
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonDeserialize(using = LocalDateTimeDeserializer.class)
	@JsonSerialize(using = LocalDateTimeSerializer.class)
	private LocalDateTime sendTime;
	// 打开链接
	@TableField(exist = false)
	private String msgUrl;
	// 发送类型
	@TableField(exist = false)
	private String sendTypeStr;
	// 发送时间
	@TableField(exist = false)
	private String sendTimeStr;

	/**
	 * 得到对象的哈希值
	 *
	 * @return int 对象的哈希值
	 */
	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(this.getLogicId()).toHashCode();
	}

	/**
	 * 比较两个对象是否相等
	 *
	 * @param other
	 *            要比较的对象
	 * @return boolean 相同返回true，否则返回flase
	 */
	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof MsgInboxObj)) {
			return false;
		}
		final MsgInboxObj castOther = (MsgInboxObj) other;
		return new EqualsBuilder().append(this.getLogicId(), castOther.getLogicId()).isEquals();
	}

	/**
	 * 返回对象的字符串值
	 *
	 * @return String 表示用户对象的字符串值
	 */
	@Override
	public String toString() {
		return new ToStringBuilder(this).append("收件箱", this.getUserName()).toString();
	}

	/**
	 * 将DATE类型的时间格式化为字符串类型
	 *
	 * @return 字符串时间
	 */
	public String getUpdateTimeStr() {
		if (this.updateTime != null) {
			this.updateTimeStr = LocalDateUtil.showTime(this.updateTime);
		}
		return this.updateTimeStr;
	}

	/**
	 * 接收时间
	 *
	 * @return 接收时间
	 */
	public String getReceiveTimeStr() {
		if (this.receiveTime != null) {
			this.receiveTimeStr = LocalDateUtil.showTime(this.receiveTime);
		}
		return receiveTimeStr;
	}

	/**
	 * 消息状态（默认0未读/1已读）
	 *
	 * @return 消息状态（默认0未读/1已读）
	 */
	public String getMsgStatusStr() {
		if (StringConstants.YES.equals(this.msgStatus)) {
			msgStatusStr = "已读";
		} else {
			msgStatusStr = "未读";
		}

		return msgStatusStr;
	}

	/**
	 * 发送类型
	 *
	 * @return 发送类型
	 */
	public String getSendTypeStr() {
		if (StringUtils.isNotEmpty(this.getSendType())) {
			final StringBuffer sb = new StringBuffer("");

			/* 短消息 */
			if (this.getSendType().indexOf(MsgObj.SENDTYPE_IM) >= 0) {
				sb.append("短消息,");
			}

			/* 邮件 */
			if (this.getSendType().indexOf(MsgObj.SENDTYPE_EMAIL) >= 0) {
				sb.append("邮件,");
			}

			/* 短信 */
			if (this.getSendType().indexOf(MsgObj.SENDTYPE_SMS) >= 0) {
				sb.append("短信,");
			}

			/* 钉钉 */
			if (this.getSendType().indexOf(MsgObj.SENDTYPE_DINGDING) >= 0) {
				sb.append("钉钉,");
			}

			if (StringUtils.isNotEmpty(sb.toString())) {
				sb.delete(sb.length() - 1, sb.length());
			}
			sendTypeStr = sb.toString();
		}
		return sendTypeStr;
	}

	public String getSendTimeStr() {
		if (this.sendTime != null) {
			this.sendTimeStr = LocalDateUtil.showTime(this.sendTime);
		}
		return sendTimeStr;
	}

	public long getId() {
		return id;
	}

	public void setId(final long id) {
		this.id = id;
	}

	public long getLogicId() {
		return logicId;
	}

	public void setLogicId(final long logicId) {
		this.logicId = logicId;
	}

	public long getOrganLogicId() {
		return organLogicId;
	}

	public void setOrganLogicId(final long organLogicId) {
		this.organLogicId = organLogicId;
	}

	public long getMsgLogicId() {
		return msgLogicId;
	}

	public void setMsgLogicId(final long msgLogicId) {
		this.msgLogicId = msgLogicId;
	}

	public String getMsgStatus() {
		return msgStatus;
	}

	public void setMsgStatus(final String msgStatus) {
		this.msgStatus = msgStatus;
	}

	public long getUserId() {
		return userId;
	}

	public void setUserId(final long userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(final String userName) {
		this.userName = userName;
	}

	public LocalDateTime getReceiveTime() {
		return receiveTime;
	}

	public void setReceiveTime(final LocalDateTime receiveTime) {
		this.receiveTime = receiveTime;
	}

	public String getMsgType() {
		return msgType;
	}

	public void setMsgType(final String msgType) {
		this.msgType = msgType;
	}

	public long getObjId() {
		return objId;
	}

	public void setObjId(final long objId) {
		this.objId = objId;
	}

	public String getSysCode() {
		return sysCode;
	}

	public void setSysCode(final String sysCode) {
		this.sysCode = sysCode;
	}

	public String getUpdatePerson() {
		return updatePerson;
	}

	public void setUpdatePerson(final String updatePerson) {
		this.updatePerson = updatePerson;
	}

	public LocalDateTime getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(final LocalDateTime updateTime) {
		this.updateTime = updateTime;
	}

	public String getExt1() {
		return ext1;
	}

	public void setExt1(final String ext1) {
		this.ext1 = ext1;
	}

	public String getExt2() {
		return ext2;
	}

	public void setExt2(final String ext2) {
		this.ext2 = ext2;
	}

	public String getExt3() {
		return ext3;
	}

	public void setExt3(final String ext3) {
		this.ext3 = ext3;
	}

	public String getExt4() {
		return ext4;
	}

	public void setExt4(final String ext4) {
		this.ext4 = ext4;
	}

	public String getExt5() {
		return ext5;
	}

	public void setExt5(final String ext5) {
		this.ext5 = ext5;
	}

	public String getMsgTitle() {
		return msgTitle;
	}

	public void setMsgTitle(final String msgTitle) {
		this.msgTitle = msgTitle;
	}

	public String getMsgContent() {
		return msgContent;
	}

	public void setMsgContent(final String msgContent) {
		this.msgContent = msgContent;
	}

	public String getSendType() {
		return sendType;
	}

	public void setSendType(final String sendType) {
		this.sendType = sendType;
	}

	public LocalDateTime getSendTime() {
		return sendTime;
	}

	public void setSendTime(final LocalDateTime sendTime) {
		this.sendTime = sendTime;
	}

	public String getMsgUrl() {
		return msgUrl;
	}

	public void setMsgUrl(final String msgUrl) {
		this.msgUrl = msgUrl;
	}

	public void setUpdateTimeStr(final String updateTimeStr) {
		this.updateTimeStr = updateTimeStr;
	}

	public void setMsgStatusStr(final String msgStatusStr) {
		this.msgStatusStr = msgStatusStr;
	}

	public void setReceiveTimeStr(final String receiveTimeStr) {
		this.receiveTimeStr = receiveTimeStr;
	}

	public void setSendTypeStr(final String sendTypeStr) {
		this.sendTypeStr = sendTypeStr;
	}

	public void setSendTimeStr(final String sendTimeStr) {
		this.sendTimeStr = sendTimeStr;
	}
}